package com.dks.businessUtil;


import java.util.List;

import javax.annotation.PostConstruct;

import com.dks.mapper.PublicDictionaryMapper;
import com.dks.mapper.RewardMapper;
import com.dks.models.Reward;
import com.dks.models.publicCompoment.PublicDictionary;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @Author: Ah Nan
 * @Description: 设置奖励值
 * @Date: 14:40 2020/5/7
 * @Modificd By:
 * @Param:
 * @return:
 * @throw: 请描述异常信息
 */
@Component
public class RewardUtil {

    @Autowired
    private RewardMapper rewardMapper;

    @Autowired
    private PublicDictionaryMapper publicDictionaryMapper;

    public static RewardUtil rewardUtil;

    public RewardUtil() {

    }

    @PostConstruct
    public void init() {
        rewardUtil = this;
        rewardUtil.rewardMapper = this.rewardMapper;
        rewardUtil.publicDictionaryMapper = this.publicDictionaryMapper;
    }

    /**
     * @Author: Ah Nan
     * @Description: 设置奖励值
     * @Date: 14:56 2020/5/7
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: rewardStatus 来源：1、完成作业，2、完成线下课，3、评价老师，4、邀请用户注册，5、邀请的用户购买了课程，6、邀请的用户体验了课程，7、完成注册
     * @return:
     * @throw: 请描述异常信息
     */
    public boolean insertReward(Long parentId, Integer rewardStatus) {


        //查找奖励值
        List<PublicDictionary> publicDictionaryList = rewardUtil.publicDictionaryMapper.getByType("REWARD");
        int rewardCount = 0;
        if (publicDictionaryList != null && publicDictionaryList.size() > 0) {
            rewardCount = Integer.valueOf(publicDictionaryList.get(0).getDictData());
        }

        Reward reward = new Reward();
        reward.setRewardCount(rewardCount);
        reward.setRewardStatus(rewardStatus);
        reward.setRewardType(1);
        reward.setParentId(parentId);

        int row = rewardUtil.rewardMapper.insert(reward);

        if (row == 1) {
            return true;
        }

        return false;
    }


}
